<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";

//'****************************************
//' N I V E L    1
//'****************************************
$strSql="select * from PROVINCIA order by des";
$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
$strid1 = SoloFun_ExecSqlFull($strSql,$arrData, $oConexion);

if($_REQUEST["CmbProvincia"]!="")
    $strid1 = $_REQUEST["CmbProvincia"];

//'****************************************
//' N I V E L    2
//'****************************************
$strSql="select * from CANTON";
$strSql .= " where id_provincia=" . $strid1;
$strSql .= " order by des";
$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
SoloFun_ExecSqlFull ($strSql, $arrData2, $oConexion);
if (empty($arrData2[0][1])) {
    $bEOF2 = true;
}

//'****************************************
//' N I V E L    3
//'****************************************
switch ($_REQUEST["opc"]) {
    case 2:
        //Canton
        $strid2=$_REQUEST["CmbCanton"];
        break;
    default:
        //Provincia
        $strid2=$arrData2[0][0];
        break;
}

$strSql="select * from PARROQUIA ";
$strSql .= " where id_ciudad=" . $strid2;
$strSql .= " order by des";

$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
if(!$oConexion->EjecutarQuery($strSql)) {
    $strERROR=1;
    $err=0;
}
$arrData3=array();
$arrData3=$oConexion->getData("NUM");

$bEOF3=false;
if (empty($arrData3[0][1])) {
    $bEOF3=true;
}
$oConexion->Cerrar();

$strSql="select (max(id)+1) as id  from PARROQUIA";
//$strSql .= " where id_ciudad=" . $strid2;

$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
if (!$oConexion->EjecutarQuery($strSql)) {
    $strERROR=1;
    $err=0;
}
$MaxId=$oConexion->getData("NUM");
$MaxId= $MaxId[0][0];

if (is_null($MaxId)) {
    $MaxId=1;
}
$oConexion->Cerrar();
?>
<html>
    <head>
        <title>Documentacion</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT></head>

    <body topmargin="0" leftmargin="0">
        <!-- Include File="includes/trn_header.asp" -->
        <p align="center" class="SoloStyle_TituloPaginas">Tabla de Parroquias</p>
        <form name="frmIngreso" action="trn_GrabaParroquia.php" method="POST">
            <table border="0" width="50%" align="center">
                <tr>
                    <td width="30%" class="SoloStyle_Etiqueta"><strong>Provincia</strong></td>
                    <td width="70%"><select name="CmbProvincia" class="SoloStyle_Texto" onChange="document.frmIngreso.opc.value=1;document.frmIngreso.action='parroquia.php';document.frmIngreso.submit()" style="width:185px">
                            <?php
                            for ($i=0; $i < count($arrData);$i++) {
                                $ind=$arrData[$i][0];
                                $jnd=$_REQUEST["CmbProvincia"];
                                if ($jnd==$ind) {
                                    echo "<option value='" . $arrData[$i][0] . "' SELECTED >" . $arrData[$i][1] . "</option>";
                                } else {
                                    echo "<option value='" . $arrData[$i][0] . "'>" . $arrData[$i][1] . "</option>";
                                }
                            }?>
                        </select></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Cant&oacute;n</b></td>
                    <td><select name="CmbCanton" class="SoloStyle_Texto" onChange="document.frmIngreso.opc.value=2;document.frmIngreso.action='parroquia.php';document.frmIngreso.submit()" style="width:185px">
                            <?php

                            if (!$bEOF2) {
                                for ($i=0;$i < count($arrData2);$i++) {
                                    
                                    $ind2=$arrData2[$i][0];
                                    $jnd2=$_REQUEST["CmbCanton"];
                                    if ($jnd2==$ind2) {

                                        echo "<option value='" . $arrData2[$i][0] . "' SELECTED >" . $arrData2[$i][2] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData2[$i][0] . "'>" . $arrData2[$i][2] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>NO HAY DATOS</option>";
                            }
                            ?>
                        </select></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">C&oacute;digo</td>
                    <td><input name="hidId1" type="text" class="SoloStyle_Texto" value="<?php echo $MaxId;?>" size="40" readonly></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Nueva Parroquia</td>
                    <td><input name="ATxtDesc" type="text" class="SoloStyle_texto" id="ATxtDesc" size="40" maxlength="50"></td>
                </tr>
            </table>
            <br><center>
                <input type="submit" name="CmdGrabar" value="Grabar" class="SoloStyle_Boton" onClick="SoloFun_Submit(document.frmIngreso)"></center>
            <input type="hidden" name="opc" value="G">
        </form>
        <table width="40%" border="0" align="center">
            <tr class="SoloStyle_Etiqueta">
                <td width="80%">Parroquia</td>
                <td width="20%">Acci&oacute;n</td>
            </tr>
            <?php for ($i=0; $i < count($arrData3);$i++) {
                $clase = "SoloStyle_Texto";
        if ($i%2 == 0 ) $clase = "SoloStyle_Grid"; ?>
            <tr class="<?php echo $clase; ?>">
                <td><?php echo $arrData3[$i][2];?></td>
                <td><a href="trn_GrabaParroquia.php?id1=<?php echo $strid1;?>&id2=<?php echo $strid2;?>&id3=<?php echo $arrData3[$i][0];?>&ds3=<?php echo $arrData3[$i][2];?>&opc=M">
                        <img src='iconos/soloico_modificar.gif' alt='Modificar' width="23" height="19" border='0' style='cursor:hand' ></a>
                    &nbsp;<a href="#" onClick="Comprobar('trn_GrabaParroquia.php?id1=<?php echo $strid1;?>&id2=<?php echo $strid2;?>&id3=<?php echo $arrData3[$i][0];?>&ds3=<?php echo $arrData3[$i][2];?>&opc=E')">
                        <img src='iconos/soloico_eliminar.gif' alt='Borrar Campos' width="23" height="19" border='0' style='cursor:hand'></a></td>
            </tr>
                <?php } ?>
        </table>
    </body>
</html>

<!--#include file="Includes/soloFun_ShowMessages.php"-->
<SCRIPT type="text/JavaScript" src="includes/fun_generales.js"></SCRIPT>

<script type="text/JavaScript">

    function Comprobar(pagina){
        var conf = confirm("Confirma Eliminar");
        if (conf)
            window.location.href = pagina;
    }

</script>